<template>
  <view class="div">
    <view class="show" v-show="flag == ''">
      <image
        src="@/static/images/slices/icon_bai_shoucang.png"
        mode=""
        v-if="!isShowV"
        @click.stop="collectFn"
      ></image>
      <image
        src="@/static/images/slices/icon_shoucang_z.png"
        mode=""
        @click.stop="collectFn"
        v-else
      ></image>
    </view>
    <view
      class="show"
      v-if="
        flag == 'my' &&
        (detailType == 'jiazu' ||
          detailType == 'myjiazu' ||
          detailType == 'myjiaxiang' ||
          detailType == 'fei' ||
          detailType == 'ling' ||
          detailType == 'shi' ||
          detailType == 'wen' ||
          detailType == 'youji')
      "
      @click.stop="goRec"
    >
      <image src="@/static/images/slices/icon_cyxq_bianji.png" mode=""></image>
    </view>
    <view class="zhuan" >
      <image
        src="@/static/images/slices/icon_bai_zhunfa.png"
        mode=""
        @click.stop="showShare"
      ></image>
    </view>

		<Share ref="refShare"  class="share_box" v-if="showShareMod"></Share>
  </view>
</template>

<script>
import Share from '@/components/share.vue'
import config from "@/config"; // 配置文件
import appShare, {
  closeShare,
} from "@/uni_modules/zhouWei-APPshare/js_sdk/appShare";
export default {
  components:{
    Share
  },
  props: {
    flag: {
      type: String,
      default: "",
    },
    from: {
      type: String,
      default: "",
    },
    collectType: {
      type: Number,
      default: 0,
    },
    id: {
      type: Number,
      default: 0,
    },
    user_id: {
      type: Number,
      default: 0,
    },
    // 收藏图标的颜色
    isShow: {
      type: Boolean,
      default: false,
    },
    // 是否是课程的收藏
    keCollect: {
      type: Boolean,
      default: false,
    },
    // 是否是一田/问道山的收藏
    yiCollect: {
      type: Boolean,
      default: false,
    },
    bookCollect: {
      type: Boolean,
      default: false,
    },
    renwuCollect: {
      type: Boolean,
      default: false,
    },
    detailType: {
      type: String,
      default: "",
    },
  },
  watch: {
    isShow: {
      deep: true, // 深度监听每一个属性值, 如果是对象可以深度监听
      immediate: true, // 进入页面后立即自动调用handler函数
      handler(newValue) {
        this.isShowV = newValue;
        // console.log(this.isShowV, "newList");
      },
    },
  },
  data() {
    return {
      // isShow: false,
      isShowV: false,
      fullPath: "",
      showShareMod:false
    };
  },
  onShow() {},
  onLoad(options) {},
  created() {
    // console.log(this.id, 1111111111111111);
  },
  methods: {
    goRec() {
      if (this.detailType == "myjiazu") {
        // 跳编辑页面
        uni.navigateTo({
          url: `/pages/detail/editMember?from=jiazu&user_id=${this.user_id}&id=${this.id}`,
        });
      } else if (this.detailType == "myjiaxiang") {
        uni.navigateTo({
          url: `/pages/detail/editMember?from=jiaxiang&user_id=${this.user_id}&id=${this.id}`,
        });
      } else if (this.detailType == "fei") {
        uni.navigateTo({
          url: `/pages/bigResult/minute_edit?type=1&id=${this.id}`,
        });
      } else if (this.detailType == "ling") {
        uni.navigateTo({
          url: `/pages/bigResult/minute_edit?type=2&id=${this.id}`,
        });
      } else if (this.detailType == "shi") {
        uni.navigateTo({
          url: `/pages/bigResult/minute_edit?type=3&id=${this.id}`,
        });
      } else if (this.detailType == "wen") {
        uni.navigateTo({
          url: `/pages/bigResult/minute_edit?type=4&id=${this.id}`,
        });
      } else if (this.detailType == "youji") {
        uni.navigateTo({
          url: `/pages/bigResult/minute_edit?type=6&id=${this.id}`,
        });
      }
    },
    // 收藏
    collectFn() {
      // 课程收藏
      if (this.keCollect) {
        this.keColFn();
        return;
      }
      if (this.yiCollect) {
        this.yiColFn();
        return;
      }
      if (this.renwuCollect) {
        this.renColFn();
        return;
      }
      // 微创收藏
      this.weiColFn();
    },

    // 微创收藏
    weiColFn() {
      this.$http
        .weichuangShoucang({
          user_id: this.user_id,
          type: this.collectType,
          id: this.id,
        })
        .then((res) => {
          // console.log(res, "微创收藏");
          uni.$u.toast(res.message);
          // setTimeout(() => {
          //   this.$emit('updateDetail')
          // }, 1000);
          this.isShowV = !this.isShowV;
        })
        .catch((error) => {
          uni.$u.toast(error);
        });
    },

    // 课程收藏接口
    keColFn() {
      this.$http
        .kechengCollect({ id: this.id })
        .then((res) => {
          // console.log(res, "课程收藏");
          uni.$u.toast(res.message);
          // setTimeout(() => {
          //   this.$emit('updateDetail')
          // }, 1000);
          this.isShowV = !this.isShowV;
        })
        .catch((error) => {
          uni.$u.toast(error);
        });
    },

    // 一田/问道山收藏
    yiColFn() {
      this.$http
        .yitianShoucang({ id: this.id })
        .then((res) => {
          // console.log(res, "一田/问道山收藏");
          uni.$u.toast(res.message);
          // setTimeout(() => {
          //   this.$emit('updateDetail')
          // }, 1000);
          this.isShowV = !this.isShowV;
        })
        .catch((error) => {
          uni.$u.toast(error);
        });
    },

    // 人物志收藏
    renColFn() {
      this.$http
        .renwuzhiShoucang({ id: this.id })
        .then((res) => {
          // console.log(res, "人物志收藏");
          uni.$u.toast(res.message);
          // setTimeout(() => {
          //   this.$emit('updateDetail')
          // }, 1000);
          this.isShowV = !this.isShowV;
        })
        .catch((error) => {
          uni.$u.toast(error);
        });
    },
    showShare() {
      this.showShareMod = true
      uni.showLoading({
				title: '加载中'
			});	
      setTimeout(() => {
        this.$refs.refShare.handleShowShare();
      }, 1000);
      
    },
    // 转发
    zhuanfa() {
      // let routes = getCurrentPages();
      // let a = this.$mp.page;
      // console.log(11111111111111);
      // console.log(a);
      // let url = getCurrentPages()[0].__page__.fullPath
      // let shareData = {
      //   shareUrl: config.uni_app_web_api_url + url,
      //   shareTitle: "分享的标题",
      //   shareContent: "分享的描述",
      //   shareImg:
      //     "http://qn.kemean.cn//upload/202004/18/1587189024467w6xj18b1.jpg",
      //   appId: "wxd0e0881530ee4444", // 默认不传type的时候，必须传appId和appPath才会显示小程序图标
      //   appPath: "pages/home/home",
      //   appWebUrl: "https://kemean.com/",
      // };
      // // 调用
      // let shareObj = appShare(shareData, (res) => {
      //   console.log("分享成功回调", res);
      //   // 分享成功后关闭弹窗
      //   // 第一种关闭弹窗的方式
      //   closeShare();
      // });
      // setTimeout(() => {
      //   // 第二种关闭弹窗的方式
      //   shareObj.close();
      // }, 5000);



      // plus.share.sendWithSystem({type:'text',content:'分享内容',href:'http://www.dcloud.io/'}, function(){
      //   console.log('分享成功');
      // }, function(e){
      //   console.log('分享失败：'+JSON.stringify(e));
      // });



      
    },
  },
};
</script>

<style scoped lang="scss">
.div {
  display: flex;
  align-items: center;
}
.show {
  width: 40rpx;
  height: 38rpx;
  image {
    width: 100%;
    height: 100%;
  }
}
.zhuan {
  width: 40rpx;
  height: 38rpx;
  margin-left: 40rpx;
  image {
    width: 100%;
    height: 100%;
  }
}
.share_box{
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 100;
}
</style>